package com.jasiri.project.adapter

import android.annotation.SuppressLint
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import com.jasiri.project.R
import com.jasiri.project.app.App
import com.jasiri.lib.baseadapter.JasiriRecyclerViewAdapter
import com.jasiri.lib.baseadapter.JasiriViewHolderHelper
import org.json.JSONObject

/**
 * Sikadwa
 * @Author wwdeng
 * @CreateTime: 2024/4/24 14:42
 * @Annotation：还款明细适配器
 */
class CreditRepayLableAdapter(recyclerView: RecyclerView?) :
    JasiriRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.item_credit_apply_detail_child) {
    override fun setItemChildListener(helper: JasiriViewHolderHelper, viewType: Int) {
//        helper.setItemChildClickListener(R.id.itemLayout) //点击Item
    }

    @SuppressLint("SetTextI18n")
    override fun fillData(helper: JasiriViewHolderHelper, position: Int, model: JSONObject) {
        val textDetailsTitle = helper.getTextView(R.id.textDetailsTitle)
        val textDetailsValue = helper.getTextView(R.id.textDetailsValue)
        val textOldValue = helper.getTextView(R.id.textOldValue)
        val discountLayout = helper.getView<ConstraintLayout>(R.id.discountLayout)
        val textDiscount = helper.getTextView(R.id.textDiscount)

        textDetailsTitle.text = model.optString("showName")
        textDetailsTitle.setTextColor(App.instance().getColor(R.color.FF999999))
        textDetailsValue.text = model.optString("showDetail")
        textDetailsValue.setTextColor(App.instance().getColor(R.color.black))

        textOldValue.visibility = View.GONE
        if (model.has("oldDetail")){
            textOldValue.visibility = View.VISIBLE
            textOldValue.text = model.optString("oldDetail")
            textDetailsValue.setTextColor(App.instance().getColor(R.color.FFFF451F))
        }
        discountLayout.visibility = View.GONE
        if (model.has("discount")){
            discountLayout.visibility = View.VISIBLE
            textDiscount.text = model.optString("discount")
        }
    }
}